#include "enemymonster.h"
#include<QDebug>
void EnemyMonster::Init(QPoint E_pos,QPixmap E_pixmap)
{
    E_speed=4;
    this->setPos(E_pos);
    this->setPixmap(E_pixmap);
     this->setScale(0.2);//缩放
}
int EnemyMonster::NowMonster=0;
int EnemyMonster::DeadMonster=0;
 void EnemyMonster:: MonsterMove(Player& player)//怪物追击函数
 {

     if(qAbs(this->x()-player.x())>qAbs(this->y()-player.y()))
     {
         if(this->x()<player.x()-15)
         {
             this->moveBy(E_speed,0);
         }
         else if(this->x()>player.x()+15)
         {
             this->moveBy(-E_speed,0);
         }
     }

     else
     {
         if(this->y()<player.y()-15)
         {
             this->moveBy(0,E_speed);
         }
         else if(this->y()>player.y()+15)
         {
             this->moveBy(0,-E_speed);
         }
     }

     if(this->x()>player.x()-80&&this->x()<player.x()+50&&this->y()>player.y()-80&&this->y()<player.y()+80)
     {
         player.blood--;
        // qDebug()<<player.blood;

     }
 }
